package com.company.manage.system.entity;

import com.company.manage.common.base.BaseEntity;
import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by HuangYong on 2016/1/22.
 * desc:
 */
@Entity
@Table(name = "t_permission")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@DynamicUpdate @DynamicInsert
public class Permission extends BaseEntity {
    private static final String TAG = "Permission";

    private static final long serialVersionUID = 1511368940157210579L;

    @Id
    @Column(name = "ID",unique = true,nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(name = "PID")
    private Integer pid;
    @Column(name = "NAME",nullable = false,length = 56)
    private String name;
    @Column(name = "TYPE",length = 20)
    private String type;
    @Column(name = "SORT")
    private Integer sort;
    @Column(name = "URL")
    private String url;
    @Column(name = "ICON")
    private String icon;
    @Column(name = "PERM_CODE",length = 56)
    private String permCode;
    @Column(name = "DESCRIPTION")
    private String description;
    @Column(name = "STATE",length = 1)
    private String state;

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "permission")
    @JsonIgnore
    private Set<RolePermission> rolePermissions = new HashSet<RolePermission>();

    public Permission() {
    }

    public Permission(String name) {
        this.name = name;
    }

    public Permission(Integer id) {
        this.id = id;
    }

    public Permission(Integer id, Integer pid, String name) {
        this.id = id;
        this.pid = pid;
        this.name = name;
    }

    public Permission(Integer pid, String name, String type, String url, String permCode) {
        this.pid = pid;
        this.name = name;
        this.type = type;
        this.url = url;
        this.permCode = permCode;
    }

    public Permission(Integer id, Integer pid, String name, String type, Integer sort, String url, String icon, String permCode, String description, String state, Set<RolePermission> rolePermissions) {
        this.id = id;
        this.pid = pid;
        this.name = name;
        this.type = type;
        this.sort = sort;
        this.url = url;
        this.icon = icon;
        this.permCode = permCode;
        this.description = description;
        this.state = state;
        this.rolePermissions = rolePermissions;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getPermCode() {
        return permCode;
    }

    public void setPermCode(String permCode) {
        this.permCode = permCode;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public Set<RolePermission> getRolePermissions() {
        return rolePermissions;
    }

    public void setRolePermissions(Set<RolePermission> rolePermissions) {
        this.rolePermissions = rolePermissions;
    }
}